// 题目: 列车调度.png
#include <stdio.h>

int main()
{
    int N;
    int arr[100000];
    int i = 0;
    int temp = 0;
    int length = 0; // 轨道个数
    scanf("%d", &N);
    for (i = 0; i < N; i++)
    {
        scanf("%d", &temp);
        if (length == 0 || arr[length - 1] < temp)
        {
            arr[length] = temp;
            length++;
        }
        else
        {
            int min = 0;
            int max = length - 1;
            int mid = (min + max) / 2;
            while (min < max)
            {
                mid = (min + max) / 2;
                if (arr[mid] > temp)
                {
                    max = mid;
                }
                else
                {
                    min = mid + 1;
                }
            }
            arr[min] = temp;
        }
    }
    printf("%d", length);
    return 0;
}